<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Park
 *
 * @property int $id
 * @property string|null $logo 园区图片
 * @property string|null $area 园区面积
 * @property int|null $park_type_id 园区类型 关联表
 * @property string|null $title 园区名称
 * @property int|null $park_format_id 园区业态
 * @property int|null $city_id 区域id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereArea($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereCityId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereLogo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereParkFormatId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereParkTypeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int|null $area_id 区域id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereAreaId($value)
 * @property int|null $area1_id 下级区域id
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereArea1Id($value)
 * @property string|null $is_hot 热度
 * @property-read \App\ParkFormat|null $parkFormat
 * @property-read \App\ParkType|null $parkType
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\model\Workshop[] $workshop
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereIsHot($value)
 * @property string|null $slider 园区图片
 * @property string|null $latitude 经度
 * @property string|null $longitude 纬度
 * @property string|null $des 园区概况
 * @property string|null $code
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\ParkBaner[] $parkBaner
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereDes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereLatitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereLongitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereSlider($value)
 * @property string|null $bottom 底部信息
 * @property int|null $park_area_id
 * @property string|null $tag
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereBottom($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereParkAreaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Park whereTag($value)
 * @property-read int|null $park_baner_count
 * @property-read int|null $workshop_count
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Park newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Park newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\Park query()
 */
class Park extends Model
{

    //
    protected $table="park";
    public static function boot()
    {
        parent::boot();
        static::saving(function ($model) {
            if($model->logo==''){
                $arr = json_decode($model->slider,true);
                if(count($arr)>=1 ){
                    $model->logo = $arr[0]['img'];
                }else{
                    $model->logo = $arr[0]['img'];
                }

            }
        });
    }
    public static function getSelectOptions()
    {
        $options = \DB::table('park')->select('id','title as text')->get();
        $selectOption = [0=>'无园区'];
        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }

    public function parkType(){
        return $this->belongsTo(ParkType::class,'park_type_id');
    }
    public function parkFormat(){
        return $this->belongsTo(ParkFormat::class,'park_format_id');
    }
    public function workshop(){
        return $this->hasMany(\App\model\Workshop::class,'park_id');
    }
    public function parkBaner(){
        return $this->hasMany(ParkBaner::class,'park_id');
    }
}
